package all;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

public abstract class All {
	public static final int U = 0;
	public static final int D = 1;
	public static final int L = 2;
	public static final int R = 3;
	protected int dir = D;
	public static final int LIVE = 0;
	public static final int DEAD = 1;
	public static final int REMOVE = 2;
	protected int state = LIVE;
	protected int size;
	protected int x;
	protected int y;

	public All() {

	}

	public All(int size, int x, int y) {
		this.size = size;
		this.x = x;
		this.y = y;
	}

	public static BufferedImage loadImage(String fileName) {
		try {
			BufferedImage image = ImageIO.read(All.class.getResource(fileName));
			return image;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException();
		}
	}

	public boolean hit(All other) {
		int x1 = this.x - other.size;
		int x2 = this.x + this.size;
		int y1 = this.y - other.size;
		int y2 = this.y + this.size;
		int x = other.x;
		int y = other.y;
		return x >= x1 && x <= x2 && y <= y2 && y >= y1;
	}

	public abstract BufferedImage getImage();

	public void paint(Graphics g) {
		g.drawImage(getImage(), x, y, null);
	}

	public boolean isLive() {
		return state == LIVE;
	}

	public boolean isDead() {
		return state == DEAD;
	}

	public boolean isRemove() {
		return state == REMOVE;
	}

	public void goDead() {
		state = DEAD;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getSize() {
		return size;
	}
}
